<template>
  <div>
    <p>Didi{{ count }}</p>
    <button @click="byebye">再见</button>
  </div>
</template>

<script>
import PubSub from "pubsub-js";
export default {
  name: "Didi",
  data() {
    return {
      count: 0,
      pubId: null,
    };
  },
  // 在初始化阶段订阅
  mounted() {
    this.pubId = PubSub.subscribe("count", (_, count) => {
      this.count = count;
    });
  },
  methods: {
    byebye() {
      PubSub.unsubscribe(this.pubId);
    },
  },
};
</script>

<style>
</style>